<?php
/**
 * 商会通讯录模块定义
 *
 * @author zh0537cn
 * @url http://s.we7.cc/
 */
 global $_W,$_GPC;
        load()->func('file');
		load()->func('tpl');
		$uniacid = $_W['uniacid'];
		$sexarr = array('未审核','通过');
		$job1 = explode(',', $this->module['config']['job1']);
		$op = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		$opp = 'citybase';
		if ('post' == $op) {
			$id = intval($_GPC['id']);
			if (!empty($id)) {
				$item = pdo_fetch('SELECT * FROM ' . tablename('bbyscm_card_cityxinxi') . (' where id=' . $id));
                $item["imgs"] = iunserializer($item["imgs"]);
             
				empty($item) ? message('亲,数据不存在！', '', 'error') : '';
			}
			if (checksubmit('submit')) {
				empty($_GPC['cardname']) ? message('姓名必填') : $cardname = $_GPC['cardname'];
				empty($_GPC['mobile']) ? message('手机号必填') : $mobile = $_GPC['mobile'];
				$images = iserializer($_GPC['imgs']);
		      	$data = array(
				'uniacid' => $_W['uniacid'],
				'avaterImg' => $_GPC['avaterImg'], 
				'cardname' => $_GPC['cardname'], 
				'mobile' => $_GPC['mobile'], 
				'cardid' => $_GPC['cardid'], 
				'imgs'=> $images,
				'cityaddress' => $_GPC['cityaddress'], 
				'cityname' => $_GPC['cityname'],
				'citydesc' => $_GPC['citydesc'],  
				'akey' => $_GPC['akey'], 
				'cityclass' => $_GPC['cityclass'],  
				'longitude' => $_GPC['g_map']['lng'], 
				'latitude' => $_GPC['g_map']['lat'], 
				'popularity' => $_GPC['popularity'], 
				'createtime' => time()
				);
				if (empty($id)) {
					pdo_insert('bbyscm_card_cityxinxi', $data);
					message('数据加成功！', $this->createWebUrl('citybase', array('op' => 'display')), 'success');
					return NULL;
				}
				
				unset($data['uniacid']);
				pdo_update('bbyscm_card_cityxinxi', $data, array('id' => $id));
				message('数据更新成功', $this->createWebUrl('citybase', array('op' => 'display')), 'success');
				return NULL;
			}

			include $this->template('web/citybase');
			return NULL;
		}

		if ('del' == $op) {
			if (isset($_GPC['delete'])) {
				$ids = implode(',', $_GPC['delete']);
				$sqls = 'delete from  ' . tablename('bbyscm_card_cityxinxi') . '  where id in(' . $ids . ')';
				pdo_query($sqls);
				message('删除成功！', referer(), 'success');
			}

			$id = intval($_GPC['id']);
			$row = pdo_fetch('SELECT id FROM ' . tablename('bbyscm_card_cityxinxi') . ' WHERE id = :id', array(':id' => $id));

			if (empty($row)) {
				message('抱歉，数据不存在或是已经被删除！', $this->createWebUrl('citybase', array('op' => 'display')), 'error');
			}

			pdo_delete('bbyscm_card_cityxinxi', array('id' => $id));
			message('删除成功！', referer(), 'success');
			return NULL;
		}

		if ('display' == $op) {
			$pindex = max(1, intval($_GPC['page']));
			$psize = 10;
			$condition = '';

			if (!empty($_GPC['keyword'])) {
				$condition .= ' AND (cardname LIKE \'%' . $_GPC['keyword'] . '%\' ' . ' OR  mobile LIKE \'%' . $_GPC['keyword'] . '%\') ';
			}

			if (!empty($_GPC['cid1'])) {
				$condition .= '   and  industry =' . $_GPC['cid1'];
			}

			$list = pdo_fetchall('SELECT *  FROM ' . tablename('bbyscm_card_cityxinxi') . ' WHERE uniacid =' . $uniacid . $condition . '  ORDER BY createtime desc, id DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize);
			$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('bbyscm_card_cityxinxi') . ' WHERE uniacid =' . $uniacid . $condition);
			$pager = pagination($total, $pindex, $psize);
			
		  if (!empty($list)) {
            foreach ($list as $key => $card) {
            $list[$key]['avaterImg'] = tomedia($card['avaterImg']);
            $imgs = iunserializer($card['imgs']);
            foreach ($imgs as $k => $imgid) {
                $imgs[$k] = tomedia($imgid);
            }
            $list[$key]['imgs'] = $imgs;
        }
		  }
			include $this->template('web/citybase');
			return NULL;
		}

		if ('shenhe' == $op) {
			$id = intval($_GPC['id']);
			$issend = intval($_GPC['akey']) == 1 ? 0 : 1;
			$data1 = array('akey' => $issend);
			pdo_update('bbyscm_card_cityxinxi', $data1, array('id' => $id));

			if ($issend == 1) {
				echo json_encode(array('a' => 1));
				return NULL;
			}

			echo json_encode(array('a' => 0));
			return NULL;
		}

		if ('jb' == $op) {
			$id = intval($_GPC['id']);

			if (!empty($id)) {
				pdo_update('bbyscm_card_cityxinxi', array('openid' => NULL), array('id' => $id));
				echo json_encode(array('status' => true));
				return NULL;
			}
            include $this->template('web/citybase');
			
			echo json_encode(array('status' => false));
		}
	


?>